package demo;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.http.*;
import okhttp3.*;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @author lingkang
 * Created by 2024/5/2
 */
public class Demo06 {
    public static void main(String[] args)  throws Exception{
        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                // .readTimeout(600, TimeUnit.SECONDS)
                // .callTimeout(600, TimeUnit.SECONDS)
                .build();

        Request.Builder builder = new Request.Builder()
                .url("https://lingkang.top/");
        builder.header("Host","lingkang.top");
        client.newCall(builder.build()).enqueue(new Callback() {
            @Override
            public void onFailure(@NotNull Call call, @NotNull IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                System.out.println(response.body().string());
            }
        });
    }
}
